<?php

Class CocktailIngredientsController extends AppController {

    public $name = 'CocktailIngredients';

    function admin_edit($id) {
        $this->set('ingredients', $this->CocktailIngredient->Ingredient->find('list'));
        if (empty($this->data)) {

            $this->data = $this->CocktailIngredient->find('first', array('conditions' => array('CocktailIngredient.id' => $id), 'fields' => array('CocktailIngredient.id', 'CocktailIngredient.cocktail_id', 'CocktailIngredient.ingredient_id', 'CocktailIngredient.size', 'Ingredient.name', 'CocktailIngredient.unit', 'CocktailIngredient.id')));
        } else {

            if ($this->CocktailIngredient->save($this->data)) {
                $this->Session->setFlash('Registro editado correctamente', 'flash_custom');
                $this->redirect(array('controller' => 'CocktailIngredients', 'action' => 'index', $this->data['CocktailIngredient']['cocktail_id']));
            } else {
                $this->Session->setFlash('Datenfehler', 'flash_custom');
            }
        }
    }

    function admin_add($cocktail_id) {
        $this->layout = "ajax";
        $this->set('cocktail_id', $cocktail_id);
        $this->set('ingredients', $this->CocktailIngredient->Ingredient->find('list'));
        if (empty($this->data)) {
            
        } else {

            if ($this->CocktailIngredient->save($this->data)) {
                $this->Session->setFlash('Registro Adicionado correctamente', 'flash_custom');
                $this->redirect(array('controller' => 'CocktailIngredients', 'action' => 'index', $cocktail_id));
            } else {
                $this->Session->setFlash('Datenfehler', 'flash_custom');
            }
        }
    }

    function admin_index($cocktail_id) {
        $this->set('cocktail_id', $cocktail_id);
        $this->paginate = array('CocktailIngredient' => array('maxLimit' => 500, 'limit' => 10, 'fields' => array('CocktailIngredient.id', 'CocktailIngredient.cocktail_id', 'CocktailIngredient.size', 'CocktailIngredient.unit', 'Ingredient.name')));
        $this->set('CocktailIngredients', $this->paginate(array('CocktailIngredient.cocktail_id' => $cocktail_id)));
    }

    function admin_delete($id, $cocktail_id) {
        if ($this->CocktailIngredient->delete($id)) {
            $this->Session->setFlash(_("Ingrediente eliminado con éxito del coctel"), "flash_custom");
            $this->redirect(array('controller' => 'CocktailIngredients', 'action' => 'index', $cocktail_id));
        }
    }

}

?>